﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Utilities;

namespace ManageTicket.Partner
{
    public partial class frmSearchCustomer : Form
    {
        #region Contructor
        public frmSearchCustomer()
        {
            InitializeComponent();
        }
        #endregion

        #region Variable
        clsMethod4All objMethod = new clsMethod4All();
        ManageTicket.Library.Common.CommonFunction clsCommonFunc = new ManageTicket.Library.Common.CommonFunction();
        public ArrayList arrResult; 
        #endregion

        #region Event
        private void frmSearchCustomer_Load(object sender, EventArgs e)
        {
            arrResult = new ArrayList();

            DataObjects.CodeType oCodeType = new DataObjects.CodeType();
            oCodeType.CodeTypeId = "";
            oCodeType.CodeTypeName = "";
            clsCommonFunc.GetListCodeType(cboKindOfCustomer, "KOC", oCodeType);
        }
        
        private void btnSearch_Click(object sender, EventArgs e)
        {
            Business.Customer boCustomer = new Business.Customer();
            Business.CodeType boCodeType = new Business.CodeType();
            DataObjects.CodeType oCodeType;

            object[] oParam = new object[6];
            oParam[0] = txtCustomerId.Text;                                     //Customer_Id
            oParam[1] = txtCustomerName.Text;                                   //Customer_Name
            oParam[2] = txtPersonRepresent.Text;                                //Person_Represent
            oParam[3] = txtPersonContact.Text;                                  //Person_Contact
            oCodeType = (DataObjects.CodeType)(cboKindOfCustomer.SelectedItem);
            oParam[4] = oCodeType != null ? oCodeType.CodeTypeId : "";          //Kind_Of_Customer
            oParam[5] = "CUR";                                                  //Status

            //goi ham search
            ArrayList arr = new ArrayList();
            arr = boCustomer.SearchCustomer(oParam);

            //danh sach tra ve
            lvwCustomer.Items.Clear();
            ListViewItem item;
            oCodeType = null;
            foreach (DataObjects.Customer oCus in arr)
            {
                item = new ListViewItem();
                item.Text = oCus.CustomerId;
                item.SubItems.Add(oCus.CustomerName);
                item.SubItems.Add(oCus.PersonRepresent);
                item.SubItems.Add(oCus.PersonContact);
                oCodeType = boCodeType.GetObjectByPK(oCus.KindOfCustomer);
                if (oCodeType != null)
                    item.SubItems.Add(oCodeType.CodeTypeName);
                else
                    item.SubItems.Add("");

                lvwCustomer.Items.Add(item);
            }
            lblCount.Text = "Tổng: " + lvwCustomer.Items.Count.ToString();
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            arrResult = new ArrayList();
            DataObjects.Customer oCus;
            foreach (ListViewItem item in lvwCustomer.CheckedItems)
            {
                oCus = new DataObjects.Customer();
                oCus.CustomerId = item.Text;
                oCus.CustomerName = item.SubItems[1].Text;

                arrResult.Add(oCus);
            }
            this.Close();
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            arrResult = new ArrayList();
            this.Close();
        }

        private void chkAll_CheckedChanged(object sender, EventArgs e)
        {
            foreach (ListViewItem item in lvwCustomer.Items)
            {
                item.Checked = chkAll.Checked;
            }
        }
        #endregion

        #region Execute
        #endregion

        #region Method
        #endregion

        
    }
}
